package com.xxg;

import com.alibaba.fastjson.JSON;
import com.xxg.curd.Curd;
import com.xxg.curd.CurdConfig;
import com.xxg.curd.impl.MasterCurd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/sys")
@RestController
public class SysController {

    private final Curd curd;

    @Autowired
    public SysController(CurdConfig config) {
        this.curd = new MasterCurd(config);
    }

    @PostMapping("/create/{tableName}")
    public Object create(@PathVariable String tableName, @RequestBody String request){
        return curd.createTable(tableName, (Map)JSON.parse(request));
    }

    @DeleteMapping("/drop/{tableName}")
    public Object drop(@PathVariable String tableName){
        return curd.dropTable(tableName);
    }

}
